// appGlobal
/**
 * newAddStaff
 */
export class newAddStaff{
    constructor(employeeName,employeePhone, gender,birthday,education,employeeId){
        this.employeeName=employeeName,
        this.employeePhone=employeePhone,
        this.gender=gender,
        this.employeeId=employeeId||""
        this.birthday= (birthday=="请选择日历")?"":birthday,
        this.education= (education=="请选择学历")?"":education ,
      
        this.loginName=employeePhone
        return  this._init({employeeName,employeePhone, gender})
    } 
    _init(data){      
        return new Promise((resolve,reject)=>{
            let flg= this._validata(data)
            if(flg){           
                resolve(this)       
            }else{         
                reject()
            }
        })
    }

    _validata(data){

        let app=getApp()
        app.globalData.newAddStaff=this
        let flg =true

        function checkMobile(s){
            var length = s.length;
            if(length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(14[0-9]{1})|)+\d{8})$/.test(s) ) 
            { 
                return true; 
            }else{ 
                return false; 
            } 
        }

        if(data.hasOwnProperty("gender")){
            // console.log(data.gender)
             if( (data.gender+"").replace(/\s+/g,"") == "1" || (data.gender+"").replace(/\s+/g,"") == "0"){
                
             }else{
                 wx.showToast({
                     icon:"none",
                     duration:2000,
                     title:"请选择性别"
                 })
                 flg=false
             }
        }
      

        if(data.hasOwnProperty("employeePhone")){
            if(checkMobile(data.employeePhone)){

            }else{
                     wx.showToast({
                    icon:"none",
                    duration:2000,
                    title:"请输入正确的手机号"
                })
                flg=false
            }
       }
 
       if(data.hasOwnProperty("employeeName")){
            if((data.employeeName+"").replace(/\s+/g,"") == ""){
               wx.showToast({
                   icon:"none",
                   duration:2000,
                   title:"请输入姓名"
               })
               flg=false
            }
       }
      
      
       return flg
    
    }

}